﻿using NB.MGJ.Common.API;
using NB.MGJ.Common.Utility;
using NB.MGJ.Model;
using NB.MGJ.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;

namespace NB.MGJ.API
{

    [ApiAuthorizeFilter]
    [ApiHandleError]
    public class ApiMGJActivityManagerController : ApiBaseController<LogOnUserModel>
    {
        
        public MarketService _mserice = new MarketService();


        [ApiVisitFilter("ActivityManager")]
        [Route("nbapi/actity/list")]
        [HttpGet]
        public IHttpActionResult GetActivtiesList(string Asearch, int pageIndex = 1, int pageSize = 10)
        {

            PagerModel pm = new PagerModel();
            pm.Page = pageIndex;
            pm.PageSize = pageSize;
            //要查询的实体
            if (LogOnUser.Distributor != 0)
            {
                if (string.IsNullOrWhiteSpace(pm.StrCondition))
                {
                    pm.StrCondition = "  ChangeLoginID=" + LogOnUser.UserID;
                }
                else
                {
                    pm.StrCondition = " and ChangeLoginID=" + LogOnUser.UserID;
                }
            }
            else
            {
                if (LogOnUser.EnterpriseId != 1)
                {
                    if (string.IsNullOrEmpty(LogOnUser.JuniorEnterprise))
                    { pm.StrCondition += "  EnterpriseId  in (0)"; }
                    else
                    { pm.StrCondition += "  EnterpriseId in (" + LogOnUser.JuniorEnterprise + ")"; }
                }
                else { pm.StrCondition = " 1=1"; }
            }
            if (!string.IsNullOrWhiteSpace(Asearch))
            {
                pm.StrCondition += "  AND Title like '%" + Asearch + "%' ";
            }
            var model = _mserice.GetActivityList(ref pm, Asearch, LogOnUser.ECode);
            return ApiSuccess(model.PageData);
        }
    }
}
